package com.cloud.bitmap;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author tangyuan2meicloud.com
 * @DATE 2021/7/11 12:17
 * @Desc
 * @Remarks
 */
public class BitMapTest {
    public final static int mask = 3;

    public final static int model = (1 << mask) - 1;

    public static void main(String[] args) {
        sort(new int[]{1, 5, 7, 2, 100000000});
    }

    public static int[] sort(int[] arrs) {
        int maxValue = Arrays.stream(arrs).max().getAsInt();
        byte[] bytes = new byte[1 + (maxValue >> mask)];
        for (int i = 0; i < arrs.length; i++) {
            int temp = arrs[i];
            bytes[temp >> mask] |= (1 << (temp & model));
        }
        int count = 0;
        ArrayList<Integer> value = new ArrayList<>(arrs.length);
        for (int i = 0; i < bytes.length; i++) {
            byte temp = bytes[i];
            if (temp == 0) {
                count += 8;
                continue;
            }
            for (int j = 0; j < 8; j++) {
                if (((temp >> j) & 1) == 1) {
                    value.add(count);
                }
                count++;
            }
        }
        System.out.println(value);
        return null;
    }

}
